<?php
/**
 * @Author: rocky
 * @Copyright: 广州拓冠科技 <http://my8m.com>
 * Date: 2019/8/29
 * Time: 10:00
 */


namespace app\shop\controller\api\v1;


use app\common\controller\BaseApiController;
use app\common\facade\Token;
use app\shop\controller\ServiceAddress;
use app\shop\model\ShopMemberAddress;
use app\shop\model\ShopServiceAddress;
use app\shop\validate\AddressValidate;

/**
 * 地址管理
 * Class Address
 * @package app\shop\controller\api\v1
 */
class Address extends BaseApiController
{
    //添加地址
    public function postInfo(){
        $data = (new AddressValidate())->goCheck();
        $data['uid'] = Token::id();
        if($data['is_default'] == 1){
            ShopMemberAddress::uid()->setField('is_default',0);
        }
        ShopMemberAddress::create($data);
        $this->successCode();
    }
    //编辑地址
    public function putInfo(){
        $data = (new AddressValidate())->goCheck();
        $data['uid'] = Token::id();
        if($data['is_default'] == 1){
            ShopMemberAddress::uid()->setField('is_default',0);
        }
        ShopMemberAddress::update($data);
        $this->successCode();
    }
    //删除地址
    public function deleteInfo(){
        $ids = $this->request->param('ids');
        ShopMemberAddress::uid()->whereIn('id',$ids)->delete();
        $this->successCode();
    }
    //地址列表
    public function getInfo(){
        $data = ShopMemberAddress::uid()->pages()->select();
        $this->successCode($data);
    }
    //自提地址
    public function getService(){
        $data = ShopServiceAddress::pages()->select();
        $this->successCode($data);
    }
}